//
//  CommonOC.m
//  callcar
//
//  Created by tulip on 2020/11/17.
//  Copyright © 2020 shian. All rights reserved.
//

#import "CommonOC.h"
@interface CommonOC(){
    int i;
}
@end
@implementation CommonOC

i=0;

+(UITextField*)textFieldDidEditing:(UITextField *)textField {
   
        if (textField.text.length > i) {
            if (textField.text.length == 4 || textField.text.length == 9 ) {//输入
                NSMutableString * str = [[NSMutableString alloc ] initWithString:textField.text];
                [str insertString:@" " atIndex:(textField.text.length-1)];
                textField.text = str;
            }if (textField.text.length >= 13 ) {//输入完成
                textField.text = [textField.text substringToIndex:13];
                
                [textField resignFirstResponder];
            }
            i = textField.text.length;
            
        }else if (textField.text.length < i){//删除
            if (textField.text.length == 4 || textField.text.length == 9) {
                textField.text = [NSString stringWithFormat:@"%@",textField.text];
                textField.text = [textField.text substringToIndex:(textField.text.length-1)];
            }
            i = textField.text.length;
        }
    return textField;
}



@end
